/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package klient;

/**
 *
 * @author nicra
 */
public class UserState {
    public static final int NO_CONNECTED=-2;
    public static final int WAIT_FOR_CONNECT=-1;
    public static final int JUST_CONNECTED=0;
    public static final int HAS_ID=1;
    public static final int IS_LOGIN=2;
    public static final int IS_PASS=3;
    public static final int LOGGED=4;
    
    public boolean wantReg=false;
    public boolean afk=false;
    public int ID=-1;
    public int IDinGame=-1;
    public String nick="";
    public String pass="";
    public int loginState=NO_CONNECTED;
    
    public int gold=30000;
    public int income=0;
    
    public long afkTime=0;
    public long lTime=0;
    
    public synchronized void setState(int nS){
        loginState=nS;
    }
    public synchronized int getState(){
        return loginState;
    }
    public boolean needLogin(){
        return (loginState==UserState.HAS_ID && !nick.isEmpty());
    }
    
    public boolean needPass(){
        return (loginState==UserState.IS_LOGIN && pass!=null);
    }
    @Override
    public String toString(){
        String out="User ";
        switch(loginState){
            case -1:
                out+="no connected";
                break;
            case 0:
                out+="only connected";
                break;
            case 4:
                out+="is authorized ";
            case 3:
                out+="has pass: ";
                out+=pass+" ";
            case 2:
                out+="has nick: ";
                out+=nick+" ";
            case 1:
                out+="has ID: ";
                out+=Integer.toString(ID)+" ";
                break;
        }
        return out;
    }
    
    public void loginErr(){
        wantReg=false;
        loginState=HAS_ID;
        nick="";
        pass="";
    }
}
